import { STUFF_TYPES } from "../../constance";
import { Handler, INPUT, OUTPUT } from '../../typings'

type ResultType = number;

type TestTemplate = (fn: Handler, type: STUFF_TYPES) => TemplateLiteralFn

export type TemplateLiteralFn = (strs: TemplateStringsArray, ...args: ResultType[]) => void;

export const testTemplate: TestTemplate = (fn, type) => (strs, ...rest) => {
  const message =
    rest.map((item, index) => `${strs[index]}${item}`).join("") +
    strs.slice(rest.length).join("");


  const input: INPUT = {
    sellIn: rest[2],
    quality: rest[3]
  }

  test(message, () => {
    expect(fn(input, type)).toEqual({
      updatedSellIn: rest[0],
      updatedQuality: rest[1]
    } as OUTPUT);
  });
};
